<?php

//include_once('superheader.php');

$m = new Mongo();

$db = $m->EMU;

$collection = $db->equipment;

$equipmentQuery = array('barcode' =>  $_POST['barcode']);

$cursor = $collection->findOne($equipmentQuery);


if($_POST['decomDate'] <= $_POST['comDate'])
{
	Header("Location: ../equipment.php?error=dateEquip");
	exit();
	//was getting an error on this when in main "if" statement below, im not sure why.
}


if($cursor == NULL && $_POST['name'] != "" && $_POST['location'] != "" && $_POST['barcode'] != "" && isset($_POST['type'] ) && isset($_POST['comDate']) && isset($_POST['decomDate']))
{
	$collection->insert(array('name' => $_POST['name'], 'location' => $_POST['location'], 'barcode' => $_POST['barcode'], 'type' => $_POST['type'], 'comDate' => $_POST['comDate'], 'decomDate' => $_POST['decomDate']));
	Header("Location: ../equipment.php");
}
else if($cursor != NULL)
{
	Header("Location: ../equipment.php?error=duplicateEquip");
}
else {
	Header("Location: ../equipment.php?error=emptyEquip");
}
?>